package com.apexedu.portal.controller;


import com.apexedu.framework.dao.BaseDao;
import com.apexedu.framework.util.DBUtil;
import com.apexedu.identity.IdConstants;
import com.apexedu.identity.entity.TSysUser;
import com.apexedu.portal.service.impl.CalendarServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 日程安排管理
 * Created on 2015.08.18
 */
@Controller
public class CalendarController {
    private static final Log LOG = LogFactory.getLog(CalendarController.class);
    @Autowired
    BaseDao baseDao;
    @Resource
    private CalendarServiceImpl service;


    /**
     * 日程安排控制类
     * @param rq 日期
     * @return
     */
    @RequestMapping(value = "/uc/c/index", method = RequestMethod.GET)
    public String index(HttpServletRequest request,ModelMap model,String rq) {
        try {
            TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
            service.loadCalendar(model,user,rq);
            return "portal/shd/calendar/index";
        } catch (Exception e) {
            LOG.error(e);
            throw new RuntimeException(e);
        }
    }

    /**
     * 月份每一天的事件，并标记出每天的事件
     * @param month 格式如：2015-08（yyyy-MM）
     * @return
     */
    @RequestMapping(value = "/uc/c/montheveryday", method = RequestMethod.POST)
    public @ResponseBody
    String montheveryday(HttpServletRequest request,String month) {
        try {
            TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
            //标记为已读
            return  service.monthEveryDay(month,user.getUserloginid());
        } catch (Exception e) {
            LOG.error(e);
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取今天的所有事情
     * @return
     */
    @RequestMapping(value = "/uc/c/today", method = RequestMethod.POST)
    public @ResponseBody
    String today(HttpServletRequest request) {
        try {
            TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
            //标记为已读
            return  service.today(user.getUserloginid());
        } catch (Exception e) {
            LOG.error(e);
            throw new RuntimeException(e);
        }
    }

}
